<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./node_modules/axios/dist/axios.min.js"></script>
</head>

<body>
    <input type="text" id="username">
    <input type="password" id="pwd">
    <button>登录</button>
    <script src="./utils/storageUtil.js"></script>
    <script>
        // console.log(axios);


        axios.interceptors.response.use(res => {
            return res.data;
        })

        let btn = document.querySelector('button');
        let username = document.querySelector('#username');
        let pwd = document.querySelector('#pwd');
        btn.onclick = async function() {
            try {
                let {
                    data
                } = await axios.post('http://localhost/admin/login', {
                    username: username.value,
                    pwd: pwd.value
                })

                //  登录成功

                // console.log(data.token);
                saveToken(data.token)

                window.location.href = './user.html';

            } catch (err) {
                alert('抱歉，请检查您的账号和密码');
            }
        }
    </script>
</body>

</html>